package com.tianbo.elfii.client.common;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.*;

public class WlanDisconnectDialog extends JPanel{

	public WlanAP connectingAP;
	
	public JButton disconnectBtn;
	public JButton cancelBtn;
	
    BufferedImage bgImg = null;
    
    public String titleStr = "SSID";
    public String apStatStr = "连接状态       已连接";
    public String apQualityStr = "信号强度       ";
    public String apEncryptTypeStr = "安全类型       ";
    public String ipStr = "IP地址        ";
    
    public Font titleStrFont;
	
	public WlanDisconnectDialog(){
		titleStrFont = new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,26);
	}
    
	public WlanDisconnectDialog(WlanAP connectingAP){
		this.connectingAP = connectingAP;
		if(connectingAP!=null){
			titleStr = connectingAP.getSSID();
			
			int quality = connectingAP.getQuality();
			
			if(quality<25){
				apQualityStr+="弱";
			}
			else if(quality>=25 && quality<50){
				apQualityStr+="较弱";
			}
			else if(quality>=50 && quality<75){
				apQualityStr+="较强";
			}
			else{
				apQualityStr+="强";
			}
			
			if(connectingAP.getEncryptedStat()){
				if(connectingAP.getEncryptType().equals("5")){
					apEncryptTypeStr += "WPA/WPA-WPA2";
				}
				else{
					apEncryptTypeStr += "WEP";
				}
			}
			else{
				apEncryptTypeStr += "无";
			}
		}
		
		if(ElfiiCommonConfigUtil.isWlanAutoIP){
			ipStr += ElfiiCommonConfigUtil.wlanAutoIP.ip;
		}
		else{
			ipStr += ElfiiCommonConfigUtil.wlanStaticIP.ip;
		}
		
		titleStrFont = new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,26);
	}
	
	public void init(){
		this.setLayout(null);
		initImg();
		initBtn();
	}
	
	public void init(boolean isPwMatch,String errorPw){
		
		this.setLayout(null);
		initImg();
		initBtn();
		
	}

	public void initImg(){
        File f;
        try {
            f=new File("resource-common/images/config/wlan/ss_03.png");
            bgImg=ImageIO.read(f);
            
        } catch(Exception e) {System.out.print(e);}
	}
	
	public void initBtn(){
		disconnectBtn = new JButton();
		cancelBtn = new JButton();
		
		disconnectBtn.setIcon(new ImageIcon("resource-common/images/login/sssss06.png"));
		cancelBtn.setIcon(new ImageIcon("resource-common/images/login/sssss07.png"));
		
		cancelBtn.setContentAreaFilled(false);
		cancelBtn.setBorder(null);
		cancelBtn.setFocusPainted(false);
		
		disconnectBtn.setContentAreaFilled(false);
		disconnectBtn.setBorder(null);
		disconnectBtn.setFocusPainted(false);

		disconnectBtn.setBounds(100, 220, 141, 44);
		cancelBtn.setBounds(304, 220, 141, 44);
		
		this.add(disconnectBtn);
		this.add(cancelBtn);
	}
	
	
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
      
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.drawImage(bgImg,null,0,0);

        g2.setColor(Color.white);
        
        
        g2.setFont(titleStrFont);
    
        g2.drawString(titleStr, 100, 55);
        
        g2.setFont(new Font(ElfiiCommonConstant.Font_Name,Font.PLAIN,14));
        
        g2.drawString(apStatStr, 80, 105);
        g2.drawString(apQualityStr, 80, 130);
        g2.drawString(apEncryptTypeStr, 80, 155);
        g2.drawString(ipStr, 85, 180);
    }
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JFrame w = new JFrame();
		w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		w.setUndecorated(true); //
		w.setSize(545, 272);
//		w.show();
		WlanDisconnectDialog dialog = new WlanDisconnectDialog();
		dialog.setBounds(0, 0, 545, 272);
		dialog.init(false,"123");
		w.setContentPane(dialog);
		w.show();
	}

}

